<!doctype html>
<html lang="en-US">
  <head>
    <link href="/assets/index.css" rel="stylesheet" type="text/css" />
    <script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.production.min.js"></script>
    <script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.production.min.js"></script>
    <script crossorigin="anonymous" src="/test-harness.js"></script>
    <script crossorigin="anonymous" src="/test-page-object.js"></script>
    <script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
    <style>
      webchat-element {
        display: contents;
      }
    </style>
  </head>
  <body>
    <webchat-element></webchat-element>

    <script>
      class WebChatElement extends HTMLElement {
        constructor() {
          super();

          this.attachShadow({ mode: 'open' });
        }

        connectedCallback() {
          const container = document.createElement('main');

          container.id = 'webchat';

          this.shadowRoot.appendChild(container);
          this.shadowRoot.appendChild(document.head.querySelector('link').cloneNode());

          const directLine = testHelpers.createDirectLineWithTranscript(
            testHelpers.transcriptNavigation.generateTranscript()
          );
          const store = testHelpers.createStore();

          window.WebChat.renderWebChat(
            {
              directLine,
              nonce: 'test',
              store,
              styleOptions: {
                stylesRoot: this.shadowRoot
              }
            },
            container
          );
        }
      }

      run(async function () {
        customElements.define('webchat-element', WebChatElement);

        pageElements.root(document.querySelector('webchat-element').shadowRoot);

        await pageConditions.uiConnected();
        await pageConditions.scrollToBottomCompleted();
        await host.snapshot();

        for (const style of document.querySelector('webchat-element').shadowRoot.querySelectorAll('style')) {
          expect(style.nonce).toBe('test');
        }
      });
    </script>
  </body>
</html>
